<?php

namespace addons\TfFutures\api\controllers;

use addons\TfFutures\common\models\Article;
use addons\TfFutures\common\models\ArticleSingle;
use common\helpers\ResultDataHelper;
use Yii;
use api\controllers\OnAuthController;

class ArticleSingleController extends OnAuthController
{
    public $modelClass = ArticleSingle::class;

    protected $optional = ['detail'];

    //查询具体文章详情
    public function actionDetail()
    {
        if (!Yii::$app->request->isGet) {
            return ResultDataHelper::api(403, '请求的方法有误');
        }
        //文章id
        $id = Yii::$app->request->get('id');

        if (empty($id)) {
            return ResultDataHelper::api(422, '缺少参数id');
        }
        $article = $this->modelClass::find()
                                    ->where(['id' => $id, 'status' => 1])
                                    ->orderBy('sort desc')
                                    ->one();
        if (empty($article)) {
            return ResultDataHelper::api(422, '该文章暂时无法访问');
        }
        return ResultDataHelper::api(200, 'success', $article);
    }

}